package com.sxt.bus.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sxt.bus.constast.BUSConstast;
import com.sxt.bus.domain.Car;
import com.sxt.bus.domain.Rent;
import com.sxt.bus.mapper.CarMapper;
import com.sxt.bus.mapper.RentMapper;
import com.sxt.bus.service.RentService;
import com.sxt.bus.vo.RentVo;
import com.sxt.sys.utils.DataGridView;
@Service
@Transactional
public class RentServiceImpl implements RentService{
	@Autowired
private RentMapper rentMapper;
	@Autowired
	private CarMapper carMapper;
	@Override
	public void addRent(RentVo rentVo) {
		// TODO Auto-generated method stub
		this.rentMapper.insertSelective(rentVo);
		Car car=new Car();
		car.setCarnumber(rentVo.getCarnumber());
		car.setIsrenting(BUSConstast.CAR_ISRENTING_TRUE);
		carMapper.updateByPrimaryKeySelective(car);
	}
	@Override
	public DataGridView queryAllRent(RentVo rentVo) {
		// TODO Auto-generated method stub
		Page<Object> page = PageHelper.startPage(rentVo.getPage(), rentVo.getRows());
		List<Rent> list = rentMapper.queryAllRent(rentVo);
		return new DataGridView(page.getTotal(), list);
	}
	@Override
	public void updateByPrimaryKeySelective(RentVo rentVo) {
		// TODO Auto-generated method stub
		this.rentMapper.updateByPrimaryKeySelective(rentVo);
	}
	@Override
	public void deleteRent(RentVo rentVo) {
		// TODO Auto-generated method stub
		Car car=new Car();
		car.setCarnumber(rentVo.getCarnumber());
		car.setIsrenting(BUSConstast.CAR_ISRENTING_FALSE);
		this.carMapper.updateByPrimaryKeySelective(car);
		this.rentMapper.deleteByPrimaryKey(rentVo.getRentid());
	}
	@Override
	public Rent selectByPrimaryKey(String rentid) {
		// TODO Auto-generated method stub
		return this.rentMapper.selectByPrimaryKey(rentid);
	}

}
